package com.stream;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Description:
 *
 * @Create 2023/12/5 22:51
 * @Version 1.0
 */
public class TestStream {
    public static void main(String[] args) {
        List<User> users = new ArrayList<>();
        User user = new User(1, "xiaoming", 20, "男");
        User user1 = new User(2, "xiaoming", 20, "男");
        User user2 = new User(3, "kunkun", 21, "男");
        User user3 = new User(4, "xiaohong", 19, "女");
        User user4 = new User(5, "xiaowang", 18, "男");
        User user5 = new User(6, "xiaohei", 22, "女");
        User user6 = new User(7, "xiaohuang", 20, "男");
        users.add(user);
        users.add(user1);
        users.add(user2);
        users.add(user3);
        users.add(user4);
        users.add(user5);
        users.add(user6);

        Map<Integer, List<User>> map = users.stream().collect(Collectors.groupingBy(User::getId));
        Map<String, List<String>> map2 = users.stream()
                .collect(Collectors.groupingBy(User::getSex, Collectors.mapping(User::getName, Collectors.toList())));

        List<String> repetition = users.stream()
                .collect(Collectors.groupingBy(User::getName, Collectors.counting()))
                .entrySet()
                .stream()
                .filter(entry -> entry.getValue() > 1)
                .map(Map.Entry::getKey)
                .collect(Collectors.toList());

        Map<Integer, String> maps = users.stream()
                .collect(Collectors.toMap(User::getId, User::getName, (k1, k2) -> k1));

    }
}
